Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath({'Ext.ux' : 'extjs4/ux'});
Ext.require([
             'Ext.grid.*',
             'Ext.data.*',
             'Ext.ux.grid.FiltersFeature',
             'Ext.ux.ajax.JsonSimlet',
             'Ext.ux.ajax.SimManager'       
]);
Ext.define('TS.view.settings.DataImport',{
	extend: 'Ext.panel.Panel',
	border: false,
	bodyPadding:0,
	layout: 'border',
	alias: 'widget.dataimport',
	title: '基础资料导入',
	initComponent:function() {
		this.items = [
		    {
		    	xtype: 'form',
		    	region: 'north',
		    	fileUpload:true,
		    	height: 120,
		    	items:[
				    {
				    	xtype: 'fieldset',
				    	title: '选择文件',
				        height:50,
				        width:700,
				    	margin:'0 0 0 10',
				    	layout: 'hbox',
				    	fieldDefaults: {
				    		labelAlign: 'right',
				    		labelWidth: 50
				    	},
				    	items: [
				    	    {
				    	    	xtype: 'filefield',
				    	    	name: 'file',
				    	    	fieldLabel: '文件名',
				    	    	width: 600,
				    	    	buttonText: '选择文件...',
				    	    	allowBlank: false
				    	    },
				    	    {
				    	    	xtype: 'button',margin:'0 0 0 15',text:'上传',action:'upload',iconCls:'button-upload'
				    	    }
				    	]
				    },
		  		    {
						xtype:'fieldset',
				        height:50,
				        width:700,
				        margin:'0 0 0 10',
				        title: '导入期间',
				        layout:'hbox',
						fieldDefaults:{
							labelAlign:'right',
							labelWidth:40
				    	},
				        items:[
			        			{
			                        xtype: 'numberfield',
			                        fieldLabel: '年份',
			                        name:'year',
			                        allowDecimals:false,
			                        width:100,
					    	    	minValue:new Date().getFullYear()-5,
					    	    	maxValue:new Date().getFullYear()+5,
					    	    	value:new Date().getFullYear(),
			                        allowBlank: false
			                    },
			        			{
			                        fieldLabel: '期间',
			                        name:'period',
			                        labelSeparator:null,
			                        xtype: 'numberfield',
			                        width:100,
			                        allowDecimals:false,
			                        allowBlank: false,
					    	    	value:new Date().getMonth()+1,
			                        minValue:1,
			                        maxValue:12
			                    },
			                    {
			                    	xtype: 'button',margin:'0 0 0 15',text:'提交',action:'submit',iconCls:'button-ok'
			                    }
			              ]
				    }
		    	]
		    },
		    {
		    	xtype:'tabpanel',
		    	region:'center',
		    	items:[
		    	    {
		    	        title:'产品与库存',
				    	layout: 'fit',
		    	    	items:[
		    	    	     {
		    	  				xtype:'gridpanel',
		    	  				itemId: 'gridProduct',
		    					header:false,
		    					border:false,
		    					//height:100,
		    					//region:'center',
		    					//selType:'checkboxmodel',//设定选择模式
		    				    features: [{
		    				        ftype: 'summary'
		    				    }],
		 					    plugins: [
 							       {
 							    	   ptype:'cellediting',
 							    	   clicksToEdit: 1
 							       }
		 						],
		    				    columns:[
		    				         {header:'产品编码',dataIndex:'productCode',width:80,editor:{xtype:'textfield'}},
		    				         {header:'产品名称',dataIndex:'productName',width:180,editor:{xtype:'textfield'},summaryType:'count',summaryRenderer:function(value,summaryData,dataIndex){return '<b>记录数：' + value + '</b>';}},
		    				         {header:'商品名',dataIndex:'busName',width:100,editor:{xtype:'textfield'}},
		    				         {header:'规格',dataIndex:'productSpec',width:100,editor:{xtype:'textfield'}},
		    				         {header:'条码',dataIndex:'barcode',width:120,editor:{xtype:'textfield'}},
		    				         {header:'单位',dataIndex:'unit',width:50,editor:{xtype:'textfield'}},
		    				         {header:'生产企业',dataIndex:'manuf',width:120,editor:{xtype:'textfield'}},
		    				         {
		    				        	 header:'中包装数',dataIndex:'innerPack',width:60,align:'right',
	  								     editor: {
						                    xtype: 'numberfield',
						                    allowBlank: false,
			                	        	fieldStyle:'text-align:right',
			                	        	allowDecimals: false
									     }		    				        		 
		    				         },
		    				         {
		    				        	 header:'箱装数',dataIndex:'boxPack',width:60,align:'right',
	  								     editor: {
							                    xtype: 'numberfield',
							                    allowBlank: false,
				                	        	fieldStyle:'text-align:right',
				                	        	allowDecimals: false
										 }		    				        		 
		    				         },
		    				         {header:'批准文号',dataIndex:'licenseNo',width:150,editor:{xtype:'textfield'}},
		    				         {
		    				        	 xtype:'checkcolumn',header:'批号管理',dataIndex:'batchMgr',width:60,stopSelection: false	    				        		  
		    				         },
		    				         {header:'税率',dataIndex:'taxRate',width:60,
		    				        	 editor:{
		    				        		 xtype:'numberfield',
		    				        		 allowBlank:false,
		    				        		 fieldStyle:'text-align:right',
		    				        		 allowDecimals:true,
		    				        		 maxValue:1,
		    				        		 minValue:0.01
		    				        	 }
		    				         },
		    				         {header:'存货地点',dataIndex:'invAddress',width:120,editor:{xtype:'textfield'}},
		    				         {
		    				        	 header:'存货数量',dataIndex:'quantity',width:70,align:'right',
	  								     editor: {
							                    xtype: 'numberfield',
							                    allowBlank: false,
				                	        	fieldStyle:'text-align:right',
				                	        	allowDecimals: true
										 }		    				        		 		    				         
		    				         },
		    				         {
		    				        	 header:'单价',dataIndex:'price',width:70,align:'right',
		    				        	 editor: {
		    				        		 xtype: 'numberfield',
		    				        		 allowBlank: false,
		    				        		 fieldStype:'text-align:right',
		    				        		 allowDecimals:true
		    				        	 }
		    				         },
		    				         {header:'批号',dataIndex:'batchNo',width:100,editor:{xtype:'textfield'}},
		    				         {
		    				        	 header:'生产日期',dataIndex:'manufDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d'),
	  								     editor: {
							                    xtype: 'datefield'
										 }		    				        		 		    				        	 
		    				         },
		    				         {
		    				        	 header:'有效期',dataIndex:'expDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d'),
		    				        	 editor:{xtype:'datefield'}
		    				         }
		    				    ],
			    				dockedItems:[{
			    					xtype:'toolbar',
			    					dock:'bottom',
			    					items:[
				    				    {
				    				    	xtype:'button',
				    				    	text:'添加行',
				    				    	iconCls:'tree-add-button',
				    				    	handler:function(button) {
				    				    		var grid = button.up('grid');
				    				    		var store = grid.getStore();
				    				    		var row = Ext.create('TS.model.ImportProductModel');
				    				    		store.add(row);
				    				    	}
				    				    },
				    				    {
				    				    	xtype:'button',
				    				    	text:'删除行',
				    				    	iconCls:'tree-del-button',
				    				    	handler:function(button) {
				    				    		var grid = button.up('grid');
				    				    		var store = grid.getStore();
				    			                var sm = grid.getSelectionModel();
				    			                Ext.Msg.confirm('删除行','您确定要删除选中的行吗?',function(button){
				    			                	if(button == 'yes') {
						    			                store.remove(sm.getSelection());
						    			                if (store.getCount() > 0) {
						    			                    sm.select(0);
						    			                }
				    			                	}
				    			                });
				    				    	}
				    				    }
			    					]
			    				}]
		    	    	     }
		    	    	 ]
		    	    },
		    	    {
		    	        title:'客户与余额',
				    	layout: 'fit',
		    	    	items:[
		    	    	    {
		    	  				xtype:'gridpanel',
		    	  				itemId:'gridCustomer',
		    					header:false,
		    					border:false,
		    					//region:'center',
		    					//selType:'checkboxmodel',//设定选择模式
		    				    features: [{
		    				        ftype: 'summary'
		    				    }],
		 					    plugins: [
 							       {
 							    	   ptype:'cellediting',
 							    	   clicksToEdit: 1
 							       }
				 				],
		    				    columns:[
		    				         {header:'客户编码',dataIndex:'custNo',width:80,editor:{xtype:'textfield'}},
		    				         {header:'客户名称',dataIndex:'custName',width:150,editor:{xtype:'textfield'},summaryType:'count',summaryRenderer:function(value,summaryData,dataIndex){return '<b>记录数:' + value + '</b>';}},
		    				         {header:'客户类型',dataIndex:'custType',width:120,renderer:function(value){if(value==1) return '客户'; else if(value==2) return '供货商'; else if(value==3) return '客户与供货商'; else return '-';},
		    				        	 editor: new Ext.form.field.ComboBox({
		    				                    typeAhead: true,
		    				                    triggerAction: 'all',
		    				                    selectOnTab: true,
		    				                    width:150,
		    				                    store: [
		    				                        ['1','客户'],
		    				                        ['2','供货商'],
		    				                        ['3','客户与供货商']
		    				                    ],
		    				                    lazyRender: true,
		    				                    listClass: 'x-combo-list-small'
		    				                })
		    				         },
		    				         {header:'联系人',dataIndex:'contactMan',width:80,editor:{xtype:'textfield'}},
		    				         {header:'电话',dataIndex:'telephone',width:80,editor:{xtype:'textfield'}},
		    				         {header:'手机',dataIndex:'mobilephone',width:100,editor:{xtype:'textfield'}},
		    				         {header:'QQ号',dataIndex:'qq',width:80,editor:{xtype:'textfield'}},
		    				         {header:'邮箱',dataIndex:'email',width:120,editor:{xtype:'textfield'}},
		    				         {header:'公司地址',dataIndex:'companyAdd',width:150,editor:{xtype:'textfield'}},
		    				         {header:'交货地址',dataIndex:'deliveryAdd',width:200,editor:{xtype:'textfield'}},
		    				         {header:'负责部门',dataIndex:'deptName',width:80,editor:{xtype:'textfield'}},
		    				         {header:'负责职员',dataIndex:'empName',width:80,editor:{xtype:'textfield'}},
		    				         {header:'应收余额',dataIndex:'arecAmount',width:80,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},
		    				        	 editor:{
		    				        		 xtype:'numberfield',
		    				        		 allowBlank:false,
		    				        		 fieldStyle:'text-align:right',
		    				        		 allowDecimals:true
		    				        	 }
		    				         },
		    				         {header:'应付余额',dataIndex:'apayAmount',width:80,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},
		    				        	 editor:{
		    				        		 xtype:'numberfield',
		    				        		 allowBlank:false,
		    				        		 fieldStyle:'text-align:right',
		    				        		 allowDecimals:true
		    				        	 }
		    				         }
		    				    ],
			    				dockedItems:[{
			    					xtype:'toolbar',
			    					dock:'bottom',
			    					items:[
				    				    {
				    				    	xtype:'button',
				    				    	text:'添加行',
				    				    	iconCls:'tree-add-button',
				    				    	handler:function(button) {
				    				    		var grid = button.up('grid');
				    				    		var store = grid.getStore();
				    				    		var row = Ext.create('TS.model.ImportCustomerModel');
				    				    		store.add(row);
				    				    	}
				    				    },
				    				    {
				    				    	xtype:'button',
				    				    	text:'删除行',
				    				    	iconCls:'tree-del-button',
				    				    	handler:function(button) {
				    				    		var grid = button.up('grid');
				    				    		var store = grid.getStore();
				    			                var sm = grid.getSelectionModel();
				    			                Ext.Msg.confirm('删除行','您确定要删除选中的行吗?',function(button){
				    			                	if(button == 'yes') {
						    			                store.remove(sm.getSelection());
						    			                if (store.getCount() > 0) {
						    			                    sm.select(0);
						    			                }
				    			                	}
				    			                });
				    				    	}
				    				    }
			    					]
			    				}]		    				    
		    	    	     }
		    	    	 ]
		    	    }
		    	]
		    }
		];
		this.callParent(arguments);
	}
});